<?php

namespace Admin\Controller;



class AboutController extends BaseController {
    //文章显示
    public function lst(){  
        $Article = M('About');
        $count = $Article->count();
        $Page = new \Think\Page($count,5);
        $show = $Page->show();
        if (I('search')==''){         
                        $order ='createtime desc';
        }else {
            $search =trim(I('search'));
            $map['title'] = array('like',"%$search%");
            $order ='createtime desc';

        }
        $Art = $Article->where($map)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('article',$Art);
        $this->assign('page',$show);
        $this->display();
        
    }
       
    //文章添加
    public function ad(){

        $Article = M('About');
        if (IS_POST){
            $data = array(
                'title' => I('title'),
                'content'=> I('content'),
                'status' => I('status'),
                'createtime' => time(),
            );
            if ($Article->create($data)){
                if ($Article->add()){
                    $this->success('新增成功',U('lst'));
                }else {
                    $this->error('新增失败！');
                }
            }else {
                $this->error($Article->getError());
            }
            return ;
        }
        $this->display();
       
    }

    //文章修改
    public function edt($id){
        

        
        $Article = M('About');
        $Art=$Article->find($id);
        $this->assign('Article',$Art);
        if (IS_POST){
            $data =array(
                'id'=>I('id'),
                'title'=>I('title'),
                'status'=>I('status'),
                'createtime'=>time(),
                'content'=>I('content'),
            );
            if ($Article->create($data)){
                if ($Article->save()){
                    $this->success('修改成功',U('lst'));
                }else {
                    $this->error('修改失败！');
                }
            }else {
                $this->error($Article->getError());
            }
        
            return ;
        }
        
        
        $this->display();
                         
        
    } 
    
    
    
    //文章单删除
    public function del($id){
        $Article =M('About');
        if ($Article->delete($id)){
            $this->success('删除成功！',U('lst'));
        }else {
            $this->error('删除失败');
        }
    

    }
    //文章全部删除
    public function del_both($id){
        
        $del_both = I('del_both');
        if ($del_both!==""){
            $del_id =implode(',', $del_both);
            $Article =M('About');
            if ($Article->delete($del_id)){
                $this->success('删除成功！',U('lst'));
            }else {
                $this->error('删除失败');
            }
        }
        
    }
    
    
   
}